package io.renren.modules.vipuser.service.impl;

import io.renren.common.utils.ConstantUtils;
import io.renren.common.utils.R;
import io.renren.modules.dictionary.dao.DictionaryDao;
import io.renren.modules.dictionary.entity.DictionaryEntity;
import io.renren.modules.user.dao.UserinfosDao;
import io.renren.modules.user.util.UserUtil;
import io.renren.modules.vipuser.entity.VipinfoCustomEntity;
import io.renren.modules.vipuser.entity.VipinfosEntity;
import io.renren.modules.vipuser.util.VipUserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.renren.modules.vipuser.dao.VipinfosDao;
import io.renren.modules.vipuser.service.VipinfosService;

/**
* @author 杨帅  
* @date 2018/10/27 15:23  
*
*/
@Service("vipinfosService")
public class VipinfosServiceImpl implements VipinfosService {
	@Autowired
	private VipinfosDao vipinfosDao;
	@Autowired
	private UserinfosDao userinfosDao;


	@Override
	public VipinfoCustomEntity queryObject(Integer vipinfoid){
		VipinfoCustomEntity vipinfoCustomEntity = vipinfosDao.queryObject(vipinfoid);
		//返回用户数据前先进行用户身份状态设置
		boolean isVip = UserUtil.isvip(vipinfosDao,userinfosDao,vipinfoCustomEntity.getUserinfoid());
		return vipinfosDao.queryObject(vipinfoid);
	}
	
	@Override
	public List<VipinfoCustomEntity> queryList(Map<String, Object> map){
		//返回用户数据前先进行用户身份状态设置
		List<VipinfoCustomEntity> oldVipinfoCustomEntities = vipinfosDao.queryList(map);
		for (VipinfoCustomEntity oldVipinfoCustomEntity : oldVipinfoCustomEntities) {
			UserUtil.isvip(vipinfosDao,userinfosDao,oldVipinfoCustomEntity.getUserinfoid());
		}
		//传入当前时间
		map.put("now",new Date());
		List<VipinfoCustomEntity> newVipinfoCustomEntities = vipinfosDao.queryList(map);
		return newVipinfoCustomEntities;
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return vipinfosDao.queryTotal(map);
	}
	
	@Override
	public void save(VipinfoCustomEntity vipinfos){
		vipinfosDao.save(vipinfos);
	}
	
	@Override
	public void update(VipinfoCustomEntity vipinfos){
		vipinfosDao.update(vipinfos);
	}
	
	@Override
	public void delete(Integer vipinfoid){
		vipinfosDao.delete(vipinfoid);
	}
	
	@Override
	public void deleteBatch(Integer[] vipinfoids){
		vipinfosDao.deleteBatch(vipinfoids);
	}

	@Override
	public int isVipUserRepetition(String userinfoid) {
		return vipinfosDao.isVipUserRepetition(userinfoid);
	}

	@Override
	public VipinfoCustomEntity queryVip(String userinfoid) {
		//返回用户数据前先进行用户身份状态设置
		boolean isVip = UserUtil.isvip(vipinfosDao,userinfosDao,userinfoid);
		return vipinfosDao.queryVip(userinfoid);
	}

	@Override
	public void updateByUserInfoId(VipinfosEntity vipinfosEntity) {
		vipinfosDao.updateByUserInfoId(vipinfosEntity);
	}

    @Override
    public void deleteBatchByUserInfoId(String[] userinfoids) {
        vipinfosDao.deleteBatchByUserInfoId(userinfoids);
    }

	@Override
	public R judgeIsDelError(int code) {
		if(code != ConstantUtils.DEL && code != ConstantUtils.DELED){
			return R.error("软删除状态码错误!");
		}
		return null;
	}

	@Override
	public VipinfosEntity queryExpirationTime(String userinfoid) {
		//返回用户数据前先进行用户身份状态设置
		UserUtil.isvip(vipinfosDao,userinfosDao,userinfoid);
		return vipinfosDao.queryExpirationTime(userinfoid);
	}

}
